import java.util.Stack;
public class Solution3 {
    //逆波兰表达式
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(int i = 0; i < tokens.length; i++) {
            String str = tokens[i];
            if(str.equals("+") || str.equals("-") || str.equals("*") || str.equals("/")) {
                Integer valB = stack.pop();
                Integer valA = stack.pop();
                switch(str) {
                    case "+":
                        stack.push(valA + valB);
                        break;
                    case "-":
                        stack.push(valA - valB);
                        break;
                    case "*":
                        stack.push(valA * valB);
                        break;
                    case "/":
                        stack.push(valA / valB);
                        break;
                }
            }else {
                stack.push(Integer.parseInt(str));
            }
        }
        return stack.pop();
    }
}
